<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>服务管理</el-breadcrumb-item>
      <el-breadcrumb-item>服务列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <!-- 搜索查询 -->
      <el-row :gutter="20">
        <el-col :span="6">
          <div>
            <el-input v-model="queryParam.address" placeholder="请输入内容" class="input-with-select" clearable></el-input>
          </div>
        </el-col>
        <el-col :span="6">
          <el-button type="primary" @click="handleSizeChange(queryParam.pageSize)">查询</el-button>
          <el-button type="primary" @click="updateOrCreateHouseClick('add')">添加房屋案例</el-button>
        </el-col>
      </el-row>
      <!-- table表格数据 start -->
      <template>
        <el-table :data="houseDataList" style="width: 100%" max-height="570">
          <!-- 数据表 -->
          <el-table-column fixed prop="address" label="地址" width="150">
          </el-table-column>
          <el-table-column prop="area" label="面积" width="120">
          </el-table-column>
          <el-table-column prop="style_text" label="风格" width="80">
          </el-table-column>
          <el-table-column prop="thumbnail" label="封面图" width="200">
          </el-table-column>
          <el-table-column prop="describe" label="描述" width="200">
          </el-table-column>
          <el-table-column prop="like_count" label="点赞数" width="80">
          </el-table-column>
          <el-table-column prop="video_path" label="视频" width="200">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="140">
            <!-- 操作 -->
            <template slot-scope="scope">
              <el-button size="mini" type="warning" icon="el-icon-edit" @click="updateOrCreateHouseClick(scope.row.id)"
                circle></el-button>
              <el-button size="mini" type="danger" icon="el-icon-delete" @click="deleteHouse(scope.$index,scope.row.id)"
                circle></el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <!-- table表格数据 end -->
      <!-- 分页  start-->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryParam.currentPage"
        :page-sizes="[10, 20, 30, 40]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="totalResult">
      </el-pagination>
      <!-- 分页  end> -->
    </el-card>
  </div>
</template>

<script>
  import {
    getProjectCaseListApi,
    deleteProjectCaseApi,
    getProjectCaseDictApi
  } from '../request/api.js'
  export default {
    data() {
      return {
        houseDataList: [],
        houseDict: {},
        totalResult: 0,
        queryParam: {
          address: '',
          style: '',
          area: '',
          currentPage: 1,
          pageSize: 10
        }
      }
    },
    created() {
      this.getHouseList()
      this.getHouseDict()
    },
    methods: {
      // 获取列表数据
      async getHouseList() {
        const {
          data: res
        } = await getProjectCaseListApi(this.queryParam)
        console.log(res)
        this.houseDataList = res.data.dataList
        this.totalResult = res.data.totalResult
      },
      async getHouseDict() {
        const {
          data: res
        } = await getProjectCaseDictApi()
        console.log(res)
        this.houseDict = res.data
      },
      // 分页事件
      handleSizeChange(newSize) {
        this.queryParam.pageSize = newSize
        this.queryParam.currentPage = 1
        this.getHouseList()
      },
      handleCurrentChange(newPage) {
        this.queryParam.currentPage = newPage
        this.getHouseList()
      },
      async deleteHouse(index, id) {
        // 删除
        const data = await deleteProjectCaseApi(id)
        if (data.status === 200 && data.data.status) {
          this.$message.success('删除成功！')
          this.houseDataList.splice(index, 1)
        }
      },
      updateOrCreateHouseClick(houseId) {
        // 跳转到编辑页
        this.$router.push({
          name: 'house_detail',
          query: {
            houseId: houseId
          }
        })
      }
    }
  }
</script>

<style>
</style>
